<template>
	<view class="container"></view>
</template>

<script setup>
	import { ref } from "vue";
	import { onShow,onLoad } from "@dcloudio/uni-app";
	import { login } from "@/api/general.js";
	import baseUrl from "@/config.js";
	onLoad((options) => {
		wxLogin(options)
	});
	
	async function wxLogin(options) {
		const redirectUrl = encodeURIComponent(`${baseUrl.wxLoginRedirectUrl}/pages/login/login`);
		if (options.code) {
			try {
				let params = {
					code: options.code,
					InviteCode: options.InviteCode || null,
				}
				let result = await login(params)
				uni.setStorageSync("token", result.token);
				location.assign("/")
			} catch (error) {
				window.location.assign(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx2f511ecc6b61661b&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_userinfo#wechat_redirect`)
			}
		} else {
			window.location.assign(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx2f511ecc6b61661b&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_userinfo#wechat_redirect`)
		}
	}
	
	
</script>

<style lang="scss">
	
</style>